<?php
include "../include/global.php";
include "../include/admin_check.php";
$xtpl = new XTemplate ("faqWrite.htm");
include "setting.php";
include "../include/function.php";

$country_id=intval($_POST['country_id']);
$faq_name=formatDataForMySql($_POST['faq_name']);
$faq_content=formatData($_POST['faq_content']);
$faq_position=intval($_POST['faq_position']);
$faq_isactive=intval($_POST['faq_isactive']);

$ID=intval(_POST('ID'));
$type=$_POST['type'];

//
$date = date("Y-m-d");
$sub_mit = $_POST['sub_mit'];
if($sub_mit=="yes"){
	if($faq_name==""){
		$error_faq_name ="Bạn phải nhập Tên <br />";
	}
	
	$str_error=$error_faq_name;
	if($str_error==""){
		if($type=="ADD"){	
			$sql="INSERT INTO ".pre_table."faq(country_id, faq_name, faq_content, faq_position, faq_isactive, lang) 
					VALUES	('".$country_id."', '".$faq_name."', '".$faq_content."', '".$faq_position."', '".$faq_isactive."', '".$lang."')";
			execSQL($sql);
		}else{
			$sql="UPDATE ".pre_table."faq SET 
						country_id='".$country_id."', 
						faq_name='".$faq_name."', 
						faq_content='".$faq_content."', 
						faq_position='".$faq_position."', 
						faq_isactive='".$faq_isactive."',
						lang='".$lang."'
						WHERE faq_id='".$ID."'";			
			execSQL($sql);
		}			

		$act = $_POST['act'];
		if($act=='save'){
			echo '<script>
				parent.document.frmData.target = "_parent";				
				parent.window.location.href="faq.php";
			</script>';
		}else{	
			echo '<script>
				parent.document.frmData.target = "_parent";	
				parent.document.frmData.faq_name.focus();			
				parent.window.location.href="faqWrite.php";
			</script>';
		}	
		
	}else{
		echo '<script>
				parent.document.frmData.target = "_parent";		
				parent.document.getElementById("err").style.display="block";
				parent.document.getElementById("err_string").innerHTML="'.$str_error.'";
			</script>';	
	}
}
?>